<template>
  <div class="login-and-vip">
    <div class="login">
        <div class="avatar-circle">
            <img :src="userStore.isLoggedIn ? userStore.userInfo.avatar || 'https://via.placeholder.com/100' : 'https://via.placeholder.com/100'" alt="未登录" />
        </div>
        <div class="login-form">
            <div class="login-status">
                <div v-if="!userStore.isLoggedIn" @click="login">
                  <div class="login-now">立即登录</div>
                </div>
                <div v-else="userStore.isLoggedIn">
                    <div class="username">{{ userStore.userInfo.nickname || '用户名' }}</div>
                    <div class="inline-items">
                        <span>用户中心</span>
                        <span class="separator">|</span>
                        <span @click="logout">退出登录</span>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="vip-card">
      <div class="vip-content">
        <div class="vip-text">开通会员,立享特权</div>
        <button class="vip-button">立即开通</button>
      </div>
    </div>
  </div>

  <div class="vip-benefits">
    <div class="benefits-title">-会员特权-</div>
    <div class="benefits-cards">
      <BenefitCard icon="FolderOpened" text="独享更多VIP专属曲库内容(不含数字专辑)" />
      <BenefitCard icon="Headset" text="为VIP提供SQ无损音质服务,听到细节" />
      <BenefitCard icon="StarFilled" text="VIP尊贵标识,优先享有新功能特权" />
    </div>
    <div class="benefits-subtitle">-会员歌单-</div>
  </div>
</template>

<script setup lang="ts">
import { inject } from 'vue';
import BenefitCard from './BenefitCard.vue';
import { useUserStore } from '@/stores/user';

const userStore = useUserStore();

// 注入登录弹窗控制方法
const loginModal = inject<{
  showLoginModal: () => void;
}>('loginModal');

const login = () => {
    // 显示登录弹窗
    loginModal?.showLoginModal();
};

const logout = () => {
    userStore.logout();
};
</script>

<style scoped>
@keyframes glow {
  0%, 100% {
    opacity: 1;
    box-shadow: 0 0 10px rgba(255, 215, 0, 0.5), 0 0 20px rgba(255, 215, 0, 0.3);
  }
  50% {
    opacity: 0.9;
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.8), 0 0 30px rgba(255, 215, 0, 0.5);
  }
}
.login-and-vip {
  width: 1514px;
  min-width: 1500px;
  max-width: 1514px;
  height: 350px;
  background-color:  #404040;

  margin: 0;
  padding: 0;
  box-sizing: border-box;
  position: relative;
  left: -50px;
}

.avatar-circle {
  width: 150px;
  height: 150px;
  border-radius: 50%;
  overflow: hidden;
  position: absolute;
  top: 50px;
  left: 10px;
  background-color: #fff;
  border: 2px solid #ccc;
}

.avatar-circle img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.login {
  width: 400px;
  height: 300px;
  position: absolute;
  top: 50px;
  left: 150px;
}

.login-form {
  width: 240px;
  height: 150px;
  position: absolute;
  top: 50px;
  left: 160px;
  color: #ffffff;
}

.login-status {
  padding: 10px 10px 10px 20px;
  text-align: left;
  margin-top: 50px;
}

.inline-items span:hover {
  color: #ff0000;
}

.separator {
  pointer-events: none;
}

.login-now:hover {
  color: #ff0000;
}

.login-status div {
  margin: 10px 0;
  cursor: pointer;
}

.username {
  font-size: 24px;
}

.inline-items {
  display: inline-block;
}

.separator {
  margin: 0 5px;
}

.vip-card {
  width: 650px;
  height: 300px;
  background: linear-gradient(to right, #FAF3E6, #F7E7CE);
  position: absolute;
  top: 50px;
  left: 700px;
  border: 1px solid #ccc;
  border-radius: 10px 10px 0 0;
  box-shadow: 0 0 10px rgba(247, 231, 206, 0.8), 0 0 20px rgba(247, 231, 206, 0.6), 0 0 30px rgba(247, 231, 206, 0.4);
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding-left: 40px;
  animation: glow 2s infinite ease-in-out;
}

.vip-content {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 20px;
}

.vip-text {
  font-size: 36px;
  font-weight: bold;
  color: #8B4513;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
  letter-spacing: 2px;
}

.vip-button {
  background-color: #000000;
  color: #ffffff;
  border: none;
  padding: 12px 24px;
  font-size: 18px;
  font-weight: bold;
  border-radius: 25px;
  cursor: pointer;
  transition: all 0.3s ease;
  letter-spacing: 1px;
}

.vip-benefits {
  width: 1514px;
  min-width: 1500px;
  max-width: 1514px;
  height: 450px;
  background-color: inherit;


  margin: 40px 0 0;
  padding: 0;
  box-sizing: border-box;
  position: relative;
  left: -50px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
}

.benefits-title {
  font-size: 28px;
  font-weight: bold;
  color: #ffffff;
  text-align: center;
  letter-spacing: 2px;
}

.benefits-subtitle {
  font-size: 28px;
  font-weight: bold;
  color: #ffffff;
  text-align: center;
  letter-spacing: 2px;
}

.benefits-cards {
  display: flex;
  justify-content: space-between;
  margin: 20px 0;
  gap: 30px;
}

</style>